package com.brainshare.system.domain.query;

import com.brainshare.common.utils.DateUtils;
import com.brainshare.common.utils.RegexUtil;
import com.brainshare.common.utils.StringUtils;
import io.jsonwebtoken.lang.Assert;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 埋点查询入参
 * @author wll
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class BuriedPointQuery {

    /**
     * 电话号码
     */
    private String phone;

    /**
     * 开始时间
     */
    private String startTime;

    /**
     * 结束时间
     */
    private String endTime;

    public static void checkParam(BuriedPointQuery buriedPointQuery) {
        if (StringUtils.isNotEmpty(buriedPointQuery.getPhone())) {
            Assert.state(RegexUtil.isValidPhone(buriedPointQuery.getPhone()), "手机号格式错误");
        }
        if (StringUtils.isNotEmpty(buriedPointQuery.getStartTime())) {
            Assert.state(RegexUtil.isValidDate(buriedPointQuery.getStartTime()), "请输入yyyy-MM-dd格式起始日期");
        }
        if (StringUtils.isNotEmpty(buriedPointQuery.getEndTime())) {
            Assert.state(RegexUtil.isValidDate(buriedPointQuery.getEndTime()), "请输入yyyy-MM-dd格式结束日期");
        }
        if (StringUtils.isNotEmpty(buriedPointQuery.getStartTime())
                && StringUtils.isNotEmpty(buriedPointQuery.getEndTime())) {
            Assert.state(StringUtils.compare(buriedPointQuery.getStartTime(), buriedPointQuery.getEndTime()) < 0, "起始日期不能大于结束日期");
        }
    }

    public static void handleParam(BuriedPointQuery buriedPointQuery){
        if (StringUtils.isNotEmpty(buriedPointQuery.getStartTime())){
            buriedPointQuery.setStartTime(buriedPointQuery.getStartTime().concat(StringUtils.SPACE).concat(DateUtils.START_TIME));
            buriedPointQuery.setEndTime(buriedPointQuery.getEndTime().concat(StringUtils.SPACE).concat(DateUtils.END_TIME));
        }
    }
}
